import { View } from "../../../../mvc/core/View";
import { GTextFormat } from "../../../../common/GTextFormat";
import { FontUtil } from "../../../../common/font/FontUtil";
import { LayerManager } from "../../../manager/LayerManager";
import { GImageBitmap } from "../../../../../com/mui/controls/GImageBitmap";
import { ObjCreate } from "../../common/ObjCreate";
import { FilterConst } from "../../../../component/gconst/FilterConst";
import { Language } from "../../../../../extend/language/Language";
import { Cache } from "../../../cache/Cache";
import { FrameTimer } from "../../../../../com/gengine/core/frame/FrameTimer";
import { TimerType } from "../../../../../com/gengine/core/frame/TimerType";
import { Global } from "../../../../../com/gengine/global/Global";
import { Dispatcher } from "../../../../mvc/core/Dispatcher";
import { DataEvent } from "../../../events/DataEvent";
import { EventName } from "../../../mvc/EventName";
import { GLabel } from "../../../../../com/mui/controls/GLabel";
import { SecTimer } from "../../../../../com/gengine/core/frame/SecTimer";
type int = number;
//class GuildTreeCountMoneyView
    
    export  class GuildTreeCountMoneyView extends View
    {
        constructor()
        {
            super();
            this._yellowTfSmall = new GTextFormat(FontUtil.songtiName, 12, 16776960, null, null, null, null, null, flash.text.TextFormatAlign.CENTER);
            this._yellowTfBig = new GTextFormat(FontUtil.songtiName, 14, 16776960, null, null, null, null, null, flash.text.TextFormatAlign.CENTER);
            this.layer = LayerManager.uiLayer;
            this.mouseChildren = false;
            this.mouseEnabled = false;
            this.createChildren();
            return;
        }

        /* internal  */createChildren(): void
        {
            this._yellowTf = new GTextFormat();
            this._yellowTf.color = 16776960;
            this._yellowTf.align = flash.text.TextFormatAlign.LEFT;
            this._yellowTf.size = 20;
            this._yellowTf.bold = true;
            this.addChild(new GImageBitmap("copy_countdownRing_bg2.png", 0, 0));
            this.addChild(new GImageBitmap("copy_countdownRing_bottle.swf", -90, -30));
            this._titleLabel = ObjCreate.createLabel("", 0, 10, 200, 30, flash.text.TextFormatAlign.CENTER, this);
            this._titleLabel.mouseEnabled = false;
            this._titleLabel.mouseChildren = false;
            this._titleLabel.setStyle("textFormat", this._yellowTfSmall);
            this._titleLabel.textField.filters = [FilterConst.glowFilter];
            this._moneyLabel = ObjCreate.createLabel(Language.getString(57493) + "  0", 0, 35, 200, 30, flash.text.TextFormatAlign.CENTER, this, true, 16776960);
            this.stageResize();
            return;
        }

        public setRing(arg1: int=-1, arg2: int=-1): void
        {
            this._ring = arg1;
            this._titleLabel.text = Language.getStringByParam(57492, arg1);
            return;
        }

        public updateRingBottleMoney(): void
        {
            var loc1=Cache.instance.guild.guildTreeTotalCoinBind;
            if (loc1 - this._lastExp >= 10000) 
            {
                this._addExpEach = 1111;
            }
            else if (loc1 - this._lastExp >= 5000) 
            {
                this._addExpEach = 111;
            }
            else 
            {
                this._addExpEach = 11;
            }
            if (!this._frame) 
            {
                this._frame = new FrameTimer();
                this._frame.addListener(TimerType.ENTERFRAME, this.onEnterFrameHandler);
            }
            if (!this._frame.running) 
            {
                this._frame.start();
            }
            return;
        }

        /* internal  */onEnterFrameHandler(arg1: FrameTimer): void
        {
            var loc1=Cache.instance.guild.guildTreeTotalCoinBind;
            this._lastExp = this._lastExp + this._addExpEach;
            if (this._lastExp > loc1) 
            {
                this._lastExp = loc1;
            }
            this._moneyLabel.setStyle("textFormat", this._yellowTfBig);
            this._moneyLabel.text = Language.getString(57493) + "  " + this._lastExp;
            if (this._lastExp >= loc1) 
            {
                if (this._frame && this._frame.running) 
                {
                    this._frame.stop();
                }
            }
            return;
        }

        public stageResize(): void
        {
            x = Global.stage.stageWidth - width + 60;
            y = 180 + 20 * Global.stage.stageHeight / 1000;
            return;
        }

        public stopTimer(): void
        {
            if (this._timer && this._timer.running) 
            {
                this._timer.stop();
            }
            return;
        }

        public /* override */ hide(): void
        {
            if (this._timer) 
            {
                this._timer.stop();
                this._timer.dispose();
                this._timer = null;
            }
            if (this._frame) 
            {
                if (this._frame.running) 
                {
                    this._frame.stop();
                }
                this._frame = null;
            }
            super.hide();
            return;
        }

        public /* override */ show(arg1: int=0, arg2: int=0): void
        {
            super.show(arg1, arg2);
            if (this.parent) 
            {
                this.parent.setChildIndex(this, 0);
            }
            Dispatcher.dispatchEvent(new DataEvent(EventName.TaskTrackShowOrHide, false));
            return;
        }

        public static /* const */RING: string="环数";

        /* internal */ /* var */_yellowTf: Object /* flash.text.TextFormat */;

        /* internal */ /* var */_yellowTfSmall: Object /* flash.text.TextFormat */;

        /* internal */ /* var */_yellowTfBig: Object /* flash.text.TextFormat */;

        /* internal */ /* var */_ringLabelBottle: Object /* flash.display.MovieClip */;

        /* internal */ /* var */_titleLabel: GLabel;

        /* internal */ /* var */_moneyLabel: GLabel;

        /* internal */ /* var */_timer: SecTimer;

        /* internal */ /* var */_timerNumSec: int;

        /* internal */ /* var */_frame: FrameTimer;

        /* internal */ /* var */_ring: int;

        /* internal */ /* var */_addExpEach: int=11;

        /* internal */ /* var */_lastExp: int;
    }
